<template>
  <div>
    <el-form :inline="true" :model="queryForm" @keyup.enter.native="getDataList('reset')">
      <el-form-item label="真实姓名">
        <el-input v-model="queryForm.contact_person" maxlength="10" placeholder="真实姓名" clearable></el-input>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="queryForm.contact_phone" type="number" maxlength="11" placeholder="手机号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getDataList('reset')">查询</el-button>
        <el-button icon="el-icon-refresh-left" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-radio-group v-model="queryForm.status" style="margin-bottom: 30px;" @change="statusChange">
      <el-radio-button :label="-1">全部</el-radio-button>
      <el-radio-button :label="0">待服务</el-radio-button>
      <el-radio-button :label="1">已捐</el-radio-button>
      <el-radio-button :label="2">未捐</el-radio-button>
    </el-radio-group>

    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
      <el-table-column align="center" label="序号" width="60">
        <template slot-scope="scope">
          <span>{{(queryForm.page - 1) * queryForm.limit + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="contact_person" header-align="center" align="center" label="联系人">
      </el-table-column>
      <el-table-column prop="contact_phone" header-align="center" align="center" label="联系电话">
      </el-table-column>
      <el-table-column prop="company_name" header-align="center" align="center" label="公司名称">
      </el-table-column>
      <el-table-column prop="is_donation" header-align="center" align="center" label="捐款意向" width="100">
        <template slot-scope="{row}">
          {{row.is_donation?'捐款':""}}
          <span v-if="row.is_donation&&row.is_offering">|</span>
          {{row.is_offering?'捐物':""}}
        </template>
      </el-table-column>
      <el-table-column prop="interest_amount" header-align="center" align="center" label="意向金额（元）">
      </el-table-column>
      <el-table-column prop="item_name" header-align="center" align="center" show-overflow-tooltip label="意向物品" width="300">
      </el-table-column>
      <el-table-column prop="isccc_lable" header-align="center" align="center" label="状态" width="100">
        <template slot-scope="{row}">
          <el-tag v-if="row.status===0">待服务</el-tag>
          <el-tag v-if="row.status===1" type="success">已捐</el-tag>
          <el-tag v-if="row.status===2" type="danger">未捐</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="apply_time" header-align="center" align="center" label="提交时间">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="{row}">
          <el-button type="text" v-if="row.status!==0" size="small" @click="openDetails(row)">查看详情</el-button>
          <el-button type="text" v-else size="small" @click="openDetails(row)">去服务</el-button>
          <!-- <el-button type="text" size="small">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="queryForm.page" :page-sizes="[10, 20, 50, 100]" :page-size="queryForm.limit" :total="total" layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <Detail :id="activeItem.id" :show.sync="detailsShow" @change="getDataList('reset')"></Detail>
  </div>
</template>

<script>
import donationApi from '@/api/donationApi.js'
import Detail from './details'
export default {
  components: {
    Detail
  },
  data () {
    return {
      queryForm: {
        limit: 10,
        page: 1,
        status: -1
      },
      dataListLoading: false,
      total: 0,
      dataList: [],
      detailsShow: false,
      activeItem: {}
    }
  },
  created () {
    this.getDataList()
  },
  methods: {
    getDataList (reset) {
      if (reset) this.queryForm.page = 1;
      this.dataListLoading = true;
      donationApi.donationPage(this.queryForm).then(res => {
        if (res && res.data.code == 200) {
          this.dataList = res.data.page.list;
          this.total = res.data.page.totalCount;
        }
        this.dataListLoading = false;
      })
    },
    reset () {
      this.queryForm = {
        limit: 10,
        page: 1,
        status: -1
      }
      this.getDataList()
    },
    statusChange () {
      this.queryForm.page = 1;
      this.getDataList()
    },
    // 打开详情弹窗
    openDetails (item) {
      this.activeItem = item;
      this.detailsShow = true;
    },
    // 每页数
    sizeChangeHandle (val) {
      this.queryForm.limit = val
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.queryForm.page = val
      this.getDataList()
    },
  }
}
</script>

<style>
.el-form--inline .el-form-item__content {
  width: auto !important;
}
input[type='number'] {
  -moz-appearance: textfield;
}
input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button {
  -webkit-appearance: none;
}
</style>